package com.xhu.rjsx2.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhu.rjsx2.pojo.Coach;
import com.xhu.rjsx2.pojo.vo.CoachVO;
import com.xhu.rjsx2.pojo.vo.PageVO;
import com.xhu.rjsx2.service.CoachService;
import com.xhu.rjsx2.mapper.CoachMapper;
import com.xhu.rjsx2.util.BeanCopyUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ZQ
 * @description 针对表【coach】的数据库操作Service实现
 * @createDate 2023-05-08 21:02:40
 */
@Service
public class CoachServiceImpl extends ServiceImpl<CoachMapper, Coach>
        implements CoachService {


    @Override
    public PageVO listAllCoachPage(Integer pageNum, Integer pageSize,String coachName,Integer coachHeight,Integer coachWeight) {
        LambdaQueryWrapper<Coach> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(!StrUtil.isBlankIfStr(coachName),Coach::getCoachName,coachName)
                .eq(!StrUtil.isBlankIfStr(coachHeight),Coach::getCoachHeight,coachHeight)
                .eq(!StrUtil.isBlankIfStr(coachWeight),Coach::getCoachWeight,coachWeight);
        Page<Coach> page = new Page<>(pageNum, pageSize);
        page(page,queryWrapper);
        List<CoachVO> coachVOList = BeanCopyUtils.copyBeanList(page.getRecords(), CoachVO.class);
        return new PageVO(coachVOList,page.getTotal());
    }


}




